package com.ecommerce.dal.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ecommerce.dal.dao.ICategoryPhotoDAO;
import com.ecommerce.dal.entity.CategoryPhoto;
import com.ecommerce.dal.util.CustomHibernateDAOSupport;

@Repository("categoryPhotoDAO")
public class CategoryPhotoDAO extends CustomHibernateDAOSupport implements
		ICategoryPhotoDAO {

	@Override
	public void save(CategoryPhoto categoryPhoto) {
		getHibernateTemplate().save(categoryPhoto);

	}

	@Override
	public void update(CategoryPhoto categoryPhoto) {
		getHibernateTemplate().update(categoryPhoto);

	}

	@Override
	public void delete(CategoryPhoto categoryPhoto) {
		getHibernateTemplate().delete(categoryPhoto);

	}

	@Override
	public List<CategoryPhoto> findByCategoryId(long categoryId) {
		List list = getHibernateTemplate()
				.find("select categoryPhoto from CategoryPhoto categoryPhoto inner join categoryPhoto.category category where category.categoryId=?",
						categoryId);
		return (list != null && list.size()>0) ?  list : null ;
	}

}
